<template>
	<view style="overflow: hidden;">
		<view class="uni-container" style="float: left;">
            <span>大转盘设置(每格为奖励现金数,概率为千分比且必须整数)</span>
			<uni-forms ref="form" validateTrigger="bind">
				<uni-forms-item label="格子1" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="roles.role1" style="width: 200px;"/>
				</uni-forms-item>
                
                <uni-forms-item label="概率1" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.gailv1" style="width: 200px;"/>
                </uni-forms-item>
                
                <uni-forms-item label="格子2" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.role2" style="width: 200px;"/>
                </uni-forms-item>
                
                <uni-forms-item label="概率2" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.gailv2" style="width: 200px;"/>
                </uni-forms-item>
                
                <uni-forms-item label="格子3" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.role3" style="width: 200px;"/>
                </uni-forms-item>
                
                <uni-forms-item label="概率3" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.gailv3" style="width: 200px;"/>
                </uni-forms-item>
                
                <uni-forms-item label="格子4" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.role4" style="width: 200px;"/>
                </uni-forms-item>
                
                <uni-forms-item label="概率4" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.gailv4" style="width: 200px;"/>
                </uni-forms-item>
                
                <uni-forms-item label="格子5" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.role5" style="width: 200px;"/>
                </uni-forms-item>
                
                <uni-forms-item label="概率5" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.gailv5" style="width: 200px;"/>
                </uni-forms-item>
                
                
                <uni-forms-item label="格子6" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.role6" style="width: 200px;"/>
                </uni-forms-item>
                
                <uni-forms-item label="概率6" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.gailv6" style="width: 200px;"/>
                </uni-forms-item>
                
                <uni-forms-item label="格子7" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.role7" style="width: 200px;"/>
                </uni-forms-item>
                
                <uni-forms-item label="概率7" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.gailv7" style="width: 200px;"/>
                </uni-forms-item>
                
                <uni-forms-item label="格子8" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.role8" style="width: 200px;"/>
                </uni-forms-item>
                
                <uni-forms-item label="概率8" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="roles.gailv8" style="width: 200px;"/>
                </uni-forms-item>
				
				<view class="uni-button-group pointer">
					<button class="uni-button uni-button-full" type="primary" :disabled="isLoading" @click="save">保存</button>
				</view>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLoading:false,
				"roles":{
					"role1": 0,
                    "role2": 0,
                    "role3": 0,
                    "role4": 0,
                    "role5": 0,
                    "role6": 0,
                    "role7": 0,
                    "role8": 0,
                    "gailv1": 0, //千分比
                    "gailv2": 0, //千分比
                    "gailv3": 0, //千分比
                    "gailv4": 0, //千分比
                    "gailv5": 0, //千分比
                    "gailv6": 0, //千分比
                    "gailv7": 0, //千分比
                    "gailv8": 0 //千分比
				},    
					
			}
		},
		methods: {
			getinfo(){
				var self = this
				this.isLoading = true
				self.data = []
				this.$request('admin/loadconfig',{id:'roles'}).then(res => {
					this.isLoading = false
					var json = res.config
					self.roles = json
					console.log(res)
				}).catch(res => {
				
				}).finally(err => {
					this.isLoading = false
				})
			},
			save(){
				var self = this
				self.isLoading = true
				delete self.roles._id;
				for(let key in self.roles){
					if(key != '_id'){
						self.roles[key] = Number(self.roles[key])
					}
				}
				console.log(self.roles)
				self.$request('admin/changeroles',{json:JSON.stringify(self.roles)}).then(res => {
					self.isLoading = false
					uni.showToast({
						title: "修改成功",
						icon: 'none',
						duration: 2000
					})
				}).catch(res => {
				
				}).finally(err => {
					this.isLoading = false
				})
			}
		},
		mounted() {
			var self = this
			self.getinfo()
		}
	}
</script>

<style>

</style>
